package j2025.j06;

import java.util.Stack;

/**
 * @Author 猫大仙
 */
public class j0608 {
    Stack<Integer> stack ;
    Stack<Integer> minstack ;
    public MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()){
            minstack.push(val);

        }else {
            Integer peekval = minstack.peek();
            if(val <= peekval){
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            return;
        }
        int popval = stack.pop();
        if(popval == minstack.peek()){
            minstack.pop();
        }
    }

    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minstack.empty()){
            return -1;
        }
        return minstack.peek();
    }
}
